const util = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    pageNum: 1,
    showNum: 6,
    list: [],
    image: 'https://oss.ztwlxx.cn//e0802201905230923548584.jpg',
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
    tarbar: [{ flag: 0, name: '非会员视频' }, { flag: 1, name: '会员视频'}],
    index:0,
    flag:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  bindchangeS(e) {
    var index = e.detail.current
    this.setData({
      list: [],
      pageNum: 1,
      index,
    })
    this.data.flag = this.data.tarbar[index].flag
    this.list()
  },
  bindscrolltolower() {
    this.data.pageNum++
    this.list('Noempty')
  },
  onLoad: function (options) {

  },
  tarbarClick(e) {
    var flag = e.currentTarget.dataset.item.flag
    this.setData({
      list: [],
      pageNum: 1,
      flag,
      index: e.currentTarget.dataset.index
    })
  },
  jump(e) {

    wx.showModal({
      title: '提示',
      content: '是否办理会员?',
      showCancel: true,
      cancelText: '取消',
      // cancelColor: '',
      confirmText: '好的',
      // confirmColor: '',
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: `/pages/Vip/Vip?stasus=false&card_id=${e.currentTarget.dataset.cardid}&index=${e.currentTarget.dataset.index}`,
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  jumps(e) {
    wx.navigateTo({
      url: '/elsePage/pages/playVideo/playVideo?id=' + e.currentTarget.dataset.id + "&flag=" + this.data.index,

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.data.pageNum=1
    this.list()
  }, 
  list(Noempty) {
    var {
      pageNum,
      page, flag
    } = this.data, that = this;
    util.API('spwx/v1.shop/video_list', {
      page: pageNum,
      flag
    }).then(res => {
      let {
        code,
        data
      } = res
      if (code == 200) {
        if (Noempty) { } else {
          that.data.list = []
        }
        that.data.list = that.data.list.concat(data.list);
        that.setData({
          list: that.data.list,
        })
        if (that.data.list.length == data.count){
          that.setData({
            loading: true,
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { 

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },
  // onReachBottom: function () {
  //   this.data.pageNum++
  //   this.list()
  // },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */


  /**
   * 用户点击右上角分享
   */
 
})